package cn.wit.test;

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;

public class Client1 {

	public static void main(String[] args) {
		
		//host主机，port端口
		try(
				Socket socket = new Socket("127.0.0.1",6666);
				
				//通过socket与服务器进行通信
				DataOutputStream outputStream = new DataOutputStream(
						new BufferedOutputStream(socket.getOutputStream()));
				
				BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
				
				//接受服务器发送过来得消息
				InputStream inputStream = socket.getInputStream();
		) {
			
			System.out.println("和服务器已经连上了。。。");
			
			while(true) {
				
				//从控制台读取一行信息
				String message = reader.readLine();
				
				outputStream.writeUTF(message);
				outputStream.flush();//强制刷新
				
				if("88".equals(message)) {
					break;
				}
				
			}
			
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
